3.3.2 Protect

Protect wraps a selected subexpression in a protective guard that changes the way in which it participates in transformations. Protected subexpressions are displayed using some form of highlighting. Protection can be removed by applying Protect to a protected subexpression. If no subexpression is selected, Protect removes the protection from every subexpression of the active expression.

A protected subexpression is treated as an unevaluable primary whose type is that of the subexpression. Protected subexpressions are useful when applying transformations that manipulate constant subexpressions.

For example, to transform a constant into the square of its root, first factor the constant. That is, 9 is factored into 3⋅3. At this point, simplification just folds the constants into 9 again. In contrast, simplification of an expression like x⋅x produces x^2. This is how the constant expression should behave to produce the required result. To achieve the desired behaviour, both instances of 3 should be protected individually: .[3]⋅.[3]. Subsequent simplification treats them as unevaluable primaries. This will result in a protected 3 raised to the power 2, or .[3]^2. To complete the example, any protected terms remaining should be unprotected.